package day21_28.day25;

import java.util.Scanner;

public class Main02 {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String str = scn.next();
            while (str.length() > 1){
                int num = 0 ;
                for (int i = 0; i < str.length(); i++) {
                    num += str.charAt(i) - '0';
                }
                str = String.valueOf(num);
            }
            System.out.println(str);
        }
    }
}
